Skip to content

csnode: check quick-start checkpoints against the chain before loading them - #10

Merged
EnzinoBB merged 1 commit into
masterfrom
fix/checkpoint-chain-binding
Oct 9, 2026
Merged

EnzinoBB merged 1 commit into
masterfrom
fix/checkpoint-chain-binding

Conversation

@EnzinoBB

@EnzinoBB EnzinoBB commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Problem (path C of the divergence map)

Upstream PR #71 bound checkpoints to the chain (head.bin: sequence and head block hash) and added a ChainVerifier hook to CachesSerializationManager::load(). But BlockChain::tryQuickStart() calls load() without a verifier.

A checkpoint saved for a block the node no longer has at that sequence (after a rollback, a fork, or caches copied from another node) is loaded as is. Balances and consensus settings then silently differ from the chain the node actually holds.

Fix (+20 lines in 3 files)

  • tryQuickStart() passes a verifier that compares the checkpoint head hash with the hash the node has at that sequence in BlockHashes, which is persisted in LMDB independently of the blocks DB.
  • On a mismatch the checkpoint is quarantined and the next older one is tried, falling back to a slow start. This is the existing behaviour for any rejected checkpoint.
  • When the check is not possible (legacy checkpoint without head, or hash unknown locally), the checkpoint is accepted as before, so no healthy node is forced into a resync.
  • The decision lives in a pure function, cs::isCheckpointOnChain().

Tests

New tests/csnode/checkpoint_tests.cpp, 4 cases: matching hash, different hash, unknown hash, checkpoint without head. nodetests 123/123.

Upstream

A single commit that applies to CREDITSCOM/node.

🤖 Generated with Claude Code

…g them

PR #71 added a chain binding to checkpoints (head.bin: sequence and head
hash) and a ChainVerifier hook to CachesSerializationManager::load(), but
BlockChain::tryQuickStart() calls load() without a verifier. A checkpoint
saved for a block the node no longer has at that sequence (after a rollback,
a fork, or caches copied from another node) is therefore loaded as is. Its
wallet balances and consensus settings then silently differ from the chain
the node actually holds.

Pass a verifier that compares the checkpoint head hash with the block hash the
node has at that sequence (BlockHashes, persisted independently of the
blocks DB). On a mismatch the checkpoint is quarantined and the next older one
is tried, falling back to a slow start; this is the existing behaviour for any
rejected checkpoint. When the check is not possible (legacy checkpoint
without head, or hash unknown locally), the checkpoint is accepted as before,
so healthy nodes are never forced into a resync.

The decision is in a pure helper, cs::isCheckpointOnChain(), covered by
tests/csnode/checkpoint_tests.cpp (4 cases). nodetests: 123/123 pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@EnzinoBB
EnzinoBB merged commit 8631177 into master Oct 9, 2026
1 check passed
EnzinoBB added a commit that referenced this pull request Nov 5, 2026
- setup-test: "tokens node" passes --node-key too. The wallet no longer takes
  the node's key from the current folder (wallet PR #7), and this wallet.toml
  says node_key = "off" (the answer was create), so "node" did not resolve and
  the {"error": ...} JSON ended in KeyError 'source'. The error is now asserted
  first.
- setup.ps1: the command printed for later quotes only the arguments that need
  it (".\credits-wallet.exe --config wallet.toml account new main"), as
  setup.sh does; the test looks for "account new main".
- both: the create option says the account is under the wallet password, one
  for every account, chosen with the first (wallet PRs #9/#10).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant